import time

from selenium import webdriver
import threading

list = {'internet explorer': 'http://127.0.0.1:4444/wd/hub','chrome': 'http://127.0.0.1:4444/wd/hub'}


def baidu(host, browser):
    driver = webdriver.Remote(command_executor=host, desired_capabilities={'platform':'ANY',
                                                    'browserName':browser,
                                                    'version':'',
                                                    'javascriptEnabled':True})

    driver.maximize_window()
    driver.implicitly_wait(30)
    driver.get("https://www.baidu.com")
    driver.find_element_by_id("kw").send_keys(browser)
    driver.find_element_by_id("su").click()
    driver.quit()


def test_multi_thread():
    threads = []
    for browser, host in list.items():
        threads.append(threading.Thread(target=baidu, args=(host, browser,)))

    for t in threads:
        t.start()

    for t in threads:
        t.join()


